package com.ycfmedical.bed.present;

import java.util.List;

import com.ycfmedical.bed.R;
import com.ycfmedical.bed.bean.EntertainItem;
import com.ycfmedical.bed.ui.fragment.EntertainFragment;
import com.ycfmedical.bed.utils.MusicUtils;
import com.ycfmedical.bed.utils.ResourceUtil;

import android.content.Context;

import cn.droidlover.xdroidmvp.log.XLog;
import cn.droidlover.xdroidmvp.mvp.XPresent;
import rx.Observable;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Presenter决定 View 行为的纯Java类（不访问任何 Android API）
 * Created by Egoist on 2017/1/19.
 */

public class EntertainPresenter extends XPresent<EntertainFragment>
{
    
    Context context;
    
    public EntertainPresenter(Context context)
    {
        this.context = context;
    }
    
    public void loadData(String type)
    {
        if (ResourceUtil.getResources().getString(R.string.entertain_tab_music).equals(type))
        {
            loadLocalMusic();// 读取本地音乐文件
        }
        else if (ResourceUtil.getResources().getString(R.string.entertain_tab_video).equals(type))
        {
            loadLocalVideo();// 读取本地视频文件
        }
    }
    
    private void loadLocalMusic()
    {
        Observable.just(MusicUtils.getMusicData(context))
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Subscriber<List<EntertainItem>>()
            {
                
                @Override
                public void onCompleted()
                {
                    XLog.d(getClass().getSimpleName(), "loadLocalMusic - onCompleted");
                }
                
                @Override
                public void onError(Throwable e)
                {
                    XLog.e(getClass().getSimpleName(), e.toString());
                }
                
                @Override
                public void onNext(List<EntertainItem> entertainItems)
                {
                    getV().showData(entertainItems);
                }
            });
        
    }
    
    private void loadLocalVideo()
    {
        
    }
}
